package exercises;

import jakarta.servlet.*;
import jakarta.servlet.http.HttpServletRequest;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-07-12
 * Time:18:22
 */
public class CatServlet implements Servlet {
    private static int count = 0;
    @Override
    public void init(ServletConfig servletConfig) throws ServletException {

    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        System.out.println("CatServlet called time: " + (++count));
        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
        String method = httpServletRequest.getMethod();
        if (method.equals("GET")) {
            doGet();
        } else if (method.equals("POST")) {
            doPost();
        }
    }
    private void doGet() {
        System.out.println("CatServlet - doGet");
    }
    private void doPost() {
        System.out.println("CatServlet - doPost");
    }
    @Override
    public String getServletInfo() {
        return "";
    }

    @Override
    public void destroy() {

    }
}
